package alan.springboot2x.zkConfigStart.config;

import alan.springboot2x.zkConfigStart.annotation.EnableZkConfig;
import alan.springboot2x.zkConfigStart.scope.RefreshScopeRegistry;
import alan.springboot2x.zkConfigStart.zookeeper.CuratorUtil;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

import java.util.Map;

/**
 * @author: Alan
 * @date: 2021/4/3 12:36
 */
public class ConfigImportSelector implements ImportSelector {

    @Override
    public String[] selectImports(AnnotationMetadata metadata) {
        Map<String, Object> defaultAttrs = metadata.getAnnotationAttributes(EnableZkConfig.class.getName(), true);
        Object mode = defaultAttrs.get("mode");
        if("zk".equals(mode.toString())){
            return new String[]{
                RefreshScopeRegistry.class.getName(),
                        CuratorUtil.class.getName()
            };
        }else if("redis".equals(mode.toString())){
            //待实现
            return new String[0];
        }
        return new String[0];
    }
}
